﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml.Serialization;

public class Address
{
    public string city = "重庆";
    public string address = "重庆市渝中区七星岗";
    public string postalCode = "40010";
}

public class Interest
{
    //将字段设置为属性字段
    [XmlAttribute]
    public int id;
    [XmlAttribute]
    public string name;
}

public class Player
{
    //设置元素名称
    [XmlElement("myName")]
    public string name = "kitty";
    //无法序列化
    private int age = 18;
    //无法序列化
    protected int speed = 10;
    //无法序列化
    internal int roundSpeed = 20;

    public float height = 170.50f;
    public float weight = 78.05f;

    public int num { get; set; }

    public string[] hobbys = new string[] { "篮球", "羽毛球", "乒乓球" };

    public List<int> numbers;
    //设置数组节点元素名称
    [XmlArray("IntList")]
    //设置数组成员元素名称
    [XmlArrayItem("Int32")]
    public List<int> weights;
    public List<Interest> interests;
    public SerizlizerDictionary<int, string> collects = new SerizlizerDictionary<int, string>(){{10,"黄金"},{20, "汽车"},{30, "古董"}};

    //无法序列化
    public Address address;

    public Player()
    {
        //注意：List有一个坑，初始值如果与定义写一起,反序列化会出现两组重复的数据
        numbers = new List<int>() { 10, 20, 30 };
        weights = new List<int>() { 10, 20, 30 };
        interests = new List<Interest>() {
            new Interest(){ id = 100, name="画画"},
            new Interest(){ id = 200, name="运动"},
            new Interest(){ id = 300, name="赛车"},
        };
    }
}